package com.common.utils
{
	import flash.display.Graphics;
	import flash.geom.Point;
	
	public class Graphics2
	{
		public function Graphics2()
		{
		}
		
		static public function drawArc(g : Graphics, centerX:Number, centerY:Number, startAngle:Number, endAngle:Number, radius:Number, direction:Number)
		/* 
		    centerX  -- the center X coordinate of the circle the arc is located on
		    centerY  -- the center Y coordinate of the circle the arc is located on
		    startAngle  -- the starting angle to draw the arc from
		    endAngle    -- the ending angle for the arc
		    radius    -- the radius of the circle the arc is located on
		    direction   -- toggle for going clockwise/counter-clockwise
		*/
		{
		    var difference:Number = Math.abs(endAngle - startAngle);
		    /* How "far" around we actually have to draw */
		    
		    var divisions:Number = Math.floor(difference / (Math.PI / 4))+1;
		    /* The number of arcs we are going to use to simulate our simulated arc */
		    
		    var span:Number    = direction * difference / (2 * divisions);
		    var controlRadius:Number    = radius / Math.cos(span);
		    
		    g.moveTo(centerX + (Math.cos(startAngle)*radius), centerY + Math.sin(startAngle)*radius);
		    var controlPoint:Point;
		    var anchorPoint:Point;
		    for(var i:Number=0; i<divisions; ++i)
		    {
		        endAngle    = startAngle + span;
		        startAngle  = endAngle + span;
		        
		        controlPoint = new Point(centerX+Math.cos(endAngle)*controlRadius, centerY+Math.sin(endAngle)*controlRadius);
		        anchorPoint = new Point(centerX+Math.cos(startAngle)*radius, centerY+Math.sin(startAngle)*radius);
		        g.curveTo(
		            controlPoint.x,
		            controlPoint.y,
		            anchorPoint.x,
		            anchorPoint.y
		        );
		    }
		}

	}
}